<?php

declare(strict_types=1);

namespace App\Amqp\Producer;

use Hyperf\Amqp\Annotation\Producer;
use Hyperf\Amqp\Message\ProducerMessage;

#[Producer(exchange: "demo", routingKey: "demo", pool: "default")]
class DemoProducer extends ProducerMessage
{
    public function __construct($params)
    {
        $id = array_key_exists('id', $params) ? $params['id'] : 0;

        // 设置不同 pool
        $this->poolName = 'demo';

        $this->payload = [
            'id' => $id,
            'data' => [
                'id' => $id,
                'username' => 'user' . $id,
                'age' => mt_rand(1, 100),
                'phone' => ''
            ]
        ];
    }
}